package xyz.icxl.kotlion.ext.binding

import androidx.databinding.BindingAdapter
import com.google.android.material.imageview.ShapeableImageView
import com.google.android.material.shape.CornerFamily
import com.google.android.material.shape.ShapeAppearanceModel

/**
 * 文件描述：[com.google.android.material.imageview.ShapeableImageView] 扩展
 *
 * 文件创建人：cxl
 *
 * 创建时间：2021 年 09月 15 日
 *
 * 文件版本：v1.0
 *
 * 版本描述：创建文件
 */

/**
 * 圆形样式
 * @param boolean [True] :设置样式；[False]:默认样式
 */
@BindingAdapter("ext_circleStyle")
fun ShapeableImageView.circleStyle(boolean: Boolean?) {
    shapeAppearanceModel = if (boolean == true)
        ShapeAppearanceModel.builder().setAllCornerSizes(ShapeAppearanceModel.PILL).build()
    else
        ShapeAppearanceModel.builder().build()
}

/**
 * 钻石样式
 * @param boolean [True] :设置样式；[False]:默认样式
 */
@BindingAdapter("ext_diamondStyle")
fun ShapeableImageView.diamondStyle(boolean: Boolean?) {
    shapeAppearanceModel = if (boolean == true)
        ShapeAppearanceModel.builder()
            .setAllCorners(CornerFamily.CUT,  /*cornerSize=*/0f)
            .setAllCornerSizes(ShapeAppearanceModel.PILL)
            .build()
    else
        ShapeAppearanceModel.builder().build()

}

/**
 * 默认样式
 * @param boolean [True] :设置样式；[False]:默认样式
 */
@BindingAdapter("ext_defaultStyle")
fun ShapeableImageView.defaultStyle(boolean: Boolean?) {
    shapeAppearanceModel = if (boolean == true)
        ShapeAppearanceModel.builder().build()
    else
        ShapeAppearanceModel.builder().build()
}

/**
 * 圆角样式
 * @param round 圆觉度数
 */
@BindingAdapter("ext_roundStyle")
fun ShapeableImageView.roundStyle(round: Float?) {
    shapeAppearanceModel = if (null != round)
        ShapeAppearanceModel.builder().setAllCornerSizes(round).build()
    else
        ShapeAppearanceModel.builder().build()
}
